<?php  
  function contact_form_validation($form) {
  
//print_r($form); die;

    $stat = new set_static_variable();

//check the corresponding concerned dept name
//chk_concerned_dept($form['field_cont_dept']);

   //Duplication in title
   //check_title_duplication($form['title'], $form['type']['#value'], $form['field_cont_dept'], 'field_cont_dept', $stat->get_nid());
   //$stat->set_nid(0);
    
	// Check bad character validation for Title and Keywords field   
  //  chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');  
   // chkbadchar($form['field_cont_desg'][0]['value']['#value'], $form['field_cont_desg']['#title'], 'field_cont_desg');
	//chkbadchar($form['field_cont_post'][0]['value']['#value'], $form['field_cont_post']['#title'], 'field_cont_post');
	//chkbadchar($form['field_cont_pincode'][0]['value']['#value'], $form['field_cont_pincode']['#title'], 'field_cont_pincode');
	
//echo "123".$form['field_cont_desg']['und'][0]['value']['#title'];
//echo "qqq".$form['field_cont_desg']['und'][0]['value']['#value'];
	
	// minimum length charcter   
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
	minilength_validation($form['field_cont_desg']['und'][0]['value']['#value'], 5, $form['field_cont_desg']['und'][0]['value']['#title'],'field_cont_desg');
	minilength_validation($form['field_cont_post']['und'][0]['value']['#value'], 5, $form['field_cont_post']['und'][0]['value']['#title'],'field_cont_post');
	
	
	 // Bad character validations  

  chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');  
  chkbadchar($form['field_cont_desg']['und'][0]['value']['#value'], $form['field_cont_desg']['und'][0]['value']['#title'],'field_cont_desg');
  
	// Email
	
	isValidEmail($form['field_cont_email'][0]['value']['#value'],$form['field_cont_email']['#title'],'field_cont_email');
	
	//phone code
	codenumber($form['field_cont_phone1'][0]['value']['#value'],$form['field_cont_phone1']['#title'],'field_cont_phone1');
	startcode($form['field_cont_phone1'][0]['value']['#value'],$form['field_cont_phone1']['#title'],'field_cont_phone1');
	
	
	codenumber($form['field_cont_phone2'][0]['value']['#value'],$form['field_cont_phone2']['#title'],'field_cont_phone2');
	startcode($form['field_cont_phone2'][0]['value']['#value'],$form['field_cont_phone2']['#title'],'field_cont_phone2');
	
	
	// phone number  
	check_integer($form['field_cont_phone'][0]['value']['#value'],$form['field_cont_phone']['#title'],'field_cont_phone');
	check_integer($form['field_cont_phone1'][0]['value']['#value'],$form['field_cont_phone1']['#title'],'field_cont_phone1');
	minilength_validation($form['field_cont_phone'][0]['value']['#value'], 6, $form['field_cont_phone']['#title'],'field_cont_phone');
	minilength_validation($form['field_cont_phone'][0]['value']['#value'], 8, $form['field_cont_phone']['#title'],'field_cont_phone');
	
	
	check_integer($form['field_cont_landline'][0]['value']['#value'],$form['field_cont_landline']['#title'],'field_cont_landline');
	check_integer($form['field_cont_phone2'][0]['value']['#value'],$form['field_cont_phone2']['#title'],'field_cont_phone2');
	minilength_validation($form['field_cont_landline'][0]['value']['#value'], 6, $form['field_cont_landline']['#title'],'field_cont_landline');
	maxlength_validation($form['field_cont_landline'][0]['value']['#value'], 8, $form['field_cont_landline']['#title'],'field_cont_landline');
	
	//mobile no
	check_integer($form['field_cont_mobile'][0]['value']['#value'],$form['field_cont_mobile']['#title'],'field_cont_mobile');
	maxlength_validation($form['field_cont_mobile'][0]['value']['#value'], 13, $form['field_cont_mobile']['#title'], 'field_cont_mobile');
	minilength_validation($form['field_cont_mobile'][0]['value']['#value'], 10, $form['field_cont_mobile']['#title'],'field_cont_mobile');
	mobilecode($form['field_cont_mobile'][0]['value']['#value'],$form['field_cont_mobile']['#title'],'field_cont_mobile');
	
	//Fax code
	codenumber($form['field_cont_cfax'][0]['value']['#value'],$form['field_cont_cfax']['#title'],'field_cont_cfax');
	startcode($form['field_cont_cfax'][0]['value']['#value'],$form['field_cont_cfax']['#title'],'field_cont_cfax');
	
	//Fax Number 
        check_integer($form['field_cont_fax'][0]['value']['#value'],$form['field_cont_fax']['#title'],'field_cont_fax');
	
	// Pin Code  field_cont_state[value]
        //echo $form['field_cont_state']['value']['#value']; 
	chkcharpincode($form['field_cont_pincode'][0]['value']['#value'],$form['field_cont_pincode']['#title'],'field_cont_pincode');
	startpincode($form['field_cont_pincode'][0]['value']['#value'],$form['field_cont_pincode']['#title'],$form['field_cont_state']['value']['#value'],'field_cont_pincode');
	check_integer($form['field_cont_pincode'][0]['value']['#value'],$form['field_cont_pincode']['#title'],'field_cont_pincode');
	
    // Reference url validation
   /* $reference_url = $form['field_cont_url'][0]['value']['#value'];
    $url_title = $form['field_cont_url']['#title'];
    $required = $form['field_cont_url']['#required'];

    check_reference_url($reference_url, $url_title, 'field_cont_url', $required);*/
	
	// Date Validation  

    check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');
	check_date_expire($form['field_retire_date']['und'][0]['value']['date']['#value'],$form['field_retire_date']['und'][0]['#title'],'field_retire_date');
	// Pin code 
	
	maxlength_validation($form['field_cont_pincode'][0]['value']['#value'], 6, $form['field_cont_pincode']['#title'], 'field_cont_pincode');
  }

  /*function contact_load_validation() {
    $stat = new set_static_variable();
    $stat->set_edit('yes');
  }*/
  
  /*function contact_form_validation($form) {
    valid_email_address($form['field_cont_email'][0]['value']['#value']);
  }*/

  function contact_presave_validation($node) {
    $reference_url = $node->field_cont_url[0]['value'];
    $node->field_cont_url[0]['value'] = url_validation($reference_url);
  }
